﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using SharpShare.Configuration;
using System.ComponentModel;

namespace SharpShare.Storage.FileSystem.Configuration {
    public class FileSystemStorageProviderConfigurationElement : SharpShare.Configuration.StorageProviderElement {
        [ConfigurationProperty("path", IsRequired = true)]
        [DisplayName("Path")]
        public string Path {
            get {
                return (string)this["path"];
            }
            set {
                this["path"] = value;
            }
        }

        public override IStorageProvider CreateStorageProvider(IConfigurationContext context) {
            FileStorageOptions options = new FileStorageOptions() {
                RootName = this.Name,
                RootPath = this.Path
            };

            TrackingFileStorageItemFactory factory = new TrackingFileStorageItemFactory(options);

            FileStorageContainer container = (FileStorageContainer)factory.Create(this.Path);

            return container;
        }
    }
}
